from matplotlib import pyplot as plt
import matplotlib.patches as mpatches

import numpy as np

# Affichage de la table
def AfficheTable(P, objets, C):
    n = len(objets)

    # Créer une matrice RGB (n+1, C+1, 3)
    mat = np.zeros((n+1, C+1, 3))

    for i in range(n+1):
        for s in range(C+1):
            if (i, s) in P:
                mat[i][s] = [0.2, 0.7, 0.3]  # Vert
            else:
                mat[i][s] = [0.85, 0.85, 0.85]  # Gris clair

    plt.close('all')
    fig, ax = plt.subplots()
    ax.imshow(mat)

    # Afficher les valeurs dans chaque case
    for i in range(n+1):
        for s in range(C+1):
            if (i, s) in P:
                valeur = P[(i, s)]
                ax.text(s, i, str(int(valeur)), ha='center', va='center',
                        color='white', fontsize=8, fontweight='bold')

    ax.set_xticks(np.arange(-0.5, C+1, 1), minor=True)
    ax.set_yticks(np.arange(-0.5, n+1, 1), minor=True)
    ax.grid(which='minor', color='black', linewidth=0.5)

    plt.xlabel('Capacité c')
    plt.ylabel('Nombre d\'éléments i')
    plt.title('Table de programmation dynamique')

    plt.show()

objets = {1:(7,4),2:(5,3),3:(3,2),4:(6,5),5:(4,2)}
C = 10
A = {}
